import defaultaxios from 'axios';
import { message } from 'antd';
import NproGress from 'nprogress';
import 'nprogress/nprogress.css';


const axios = defaultaxios.create({
  baseURL: 'http://fangadmin.shbwyz.com',
});
// 白名单
const whiteList = [
  {
    method: 'get',
    url: '/customer',
  },
  {
    method:'get',
    url:'/api/getHouselist'
  }
];

defaultaxios.interceptors.response.use((config) => {
  NproGress.start();
  return config;
});
defaultaxios.interceptors.response.use((data) => {
    // console.log(data.config.method)
    const flag = whiteList.some(item =>item.method === data.config.method && item.url ===  data.config.url)
    NproGress.done();
    // console.log(flag)
    if(flag) {
        message.success('请求成功');
    }
  return data;
},(error)=>{
    message.error(error.message)
// console.log(error)
});

axios.interceptors.request.use((config) => {
  config.headers.Authorization = sessionStorage.getItem('token')
    ? sessionStorage.getItem('token')
    : '';
  return config;
});

axios.interceptors.response.use((config) => {
  return config;
});

export { defaultaxios, axios };
